package com.jf.concurrent.queue.disruptor.consumer;

import com.jf.concurrent.queue.disruptor.model.MessageModel;
import com.lmax.disruptor.EventHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * 构造EventHandler-消费者
 */
@Slf4j
public class MessageEventHandler implements EventHandler<MessageModel> {
    @Override
    public void onEvent(MessageModel event, long sequence, boolean endOfBatch) throws Exception {
	try {
	    //这里停止1000ms是为了确定消费消息是异步的
	    Thread.sleep(1000);
	    log.info("消费者处理消息开始");
	    if (event != null) {
		log.info("消费者消费的信息是：{}", event);
	    }
	} catch (Exception e) {
	    log.info("消费者处理消息失败");
	}
	log.info("消费者处理消息结束");
    }
}
